package a.f.h.d;

import a.c.a;
import a.c.e;
import a.c.x;
import a.i.mb;

import java.util.ArrayList;

public class z
  implements q
{
  private static final boolean a = false;
  private a.c.q b;
  private int[] d;
  private int[] e;
  private int[] f;
  private int[] g;
  private int[] h;
  private d[] i;
  private int j;
  private int k;
  private a_ l = new a_();
  private a.i.a.m m;
  private x n;
  private ArrayList o;
  private ArrayList p;
  private a.c.d[] q;
  private a.c.d[] r;
  private a.c.d[][] s;
  private a.c.d[][] t;
  public static int u;
  
  public String a()
  {
    return this.l.toString();
  }
  
  public void a(x paramx)
  {
    this.n = paramx;
  }
  
  public int a(a.c.q paramq, e parame1, e parame2, a.c.n paramn1, a.c.n paramn2, int paramInt, ArrayList paramArrayList1, ArrayList paramArrayList2, a.c.n paramn3, a.c.n paramn4)
  {
    int i5 = j.r;
    boolean bool = j.q;
    this.j = paramq.m();
    this.k = paramq.k();
    this.b = paramq;
    this.d = new int[this.j];
    this.e = new int[this.j];
    this.f = new int[this.k];
    this.i = new d[this.j];
    this.g = new int[this.k];
    this.h = new int[this.j];
    Object[] arrayOfObject = new Object[this.k];
    int[] arrayOfInt = new int[this.j];
    this.q = new a.c.d[this.j];
    this.r = new a.c.d[this.j];
    this.s = new a.c.d[2][4];
    this.t = new a.c.d[2][4];
    this.p = paramArrayList2;
    this.o = new ArrayList(paramq.k());
    this.l.a();
    this.m = new a.i.a.d(paramq);
    Object localObject1 = 0;
    if (localObject1 < paramArrayList1.size()) {}
    label312:
    do
    {
      localObject2 = (d)paramArrayList1.get(localObject1);
      if (bool) {
        break label341;
      }
      localObject4 = ((d)localObject2).b();
      do
      {
        do
        {
          if (!((a.c.m)localObject4).e()) {
            break label312;
          }
          a.c.d locald1 = ((a.c.m)localObject4).a();
          int i2 = locald1.d();
          this.i[i2] = localObject2;
          this.d[i2] = ((d)localObject2).a();
          if (bool) {
            break;
          }
          if (this.d[i2] < 0) {
            throw new a("found negative capacity");
          }
          ((a.c.m)localObject4).f();
        } while (!bool);
        localObject1++;
      } while (i5 != 0);
      if (!bool) {
        break;
      }
      localObject1 = paramInt;
    } while (i5 != 0);
    label341:
    Object localObject2 = this.b.w();
    do
    {
      if (!((a.c.m)localObject2).e()) {
        break;
      }
      localObject4 = ((a.c.m)localObject2).a();
      int i1 = ((a.c.d)localObject4).d();
      this.e[i1] = paramn1.getInt(localObject4);
      arrayOfInt[i1] = this.d[i1];
      this.q[localObject4.d()] = ((a.c.d)paramn4.get(localObject4));
      this.r[localObject4.d()] = ((a.c.d)paramn3.get(localObject4));
      ((a.c.m)localObject2).f();
      if ((i5 == 0) && (bool)) {
        break label836;
      }
    } while (!bool);
    Object localObject5;
    label664:
    int i3;
    if (i5 == 0)
    {
      if (localObject1 >= 1)
      {
        this.l.c += 1;
        a(parame1, parame2, this.e, arrayOfInt, this.h, arrayOfObject);
      }
      label781:
      label812:
      label833:
      label836:
      while (i5 != 0)
      {
        if (bool) {
          break label842;
        }
        localObject4 = localObject1;
        localObject5 = parame2;
        a.c.d locald2;
        int i4;
        do
        {
          do
          {
            if (localObject5 == parame1) {
              break;
            }
            Object localObject6 = arrayOfObject[localObject5.f()];
            if ((i5 != 0) || ((localObject6 instanceof a.c.d)))
            {
              locald2 = (a.c.d)localObject6;
              i4 = locald2.d();
              if (localObject5 == locald2.f())
              {
                localObject3 = arrayOfInt[i4];
                localObject5 = locald2.e();
                if (i5 != 0) {
                  continue;
                }
                if (!bool) {}
              }
              else
              {
                localObject3 = this.h[i4];
                localObject5 = locald2.f();
                if (i5 != 0) {
                  continue;
                }
                if (!bool) {}
              }
            }
            else
            {
              throw new RuntimeException("Unknown predecesor type !");
            }
          } while (localObject3 >= localObject4);
          localObject4 = localObject3;
          if (i5 != 0) {
            break label833;
          }
          if ((i5 == 0) && (bool)) {
            break label664;
          }
        } while (!bool);
        localObject5 = parame2;
        do
        {
          do
          {
            do
            {
              if (localObject5 == parame1) {
                break;
              }
              i3 = ((e)localObject5).f();
            } while (!(arrayOfObject[i3] instanceof a.c.d));
            locald2 = (a.c.d)arrayOfObject[i3];
            i4 = locald2.d();
            if ((i5 != 0) || (bool)) {
              break;
            }
            if (localObject5 != locald2.f()) {
              break label781;
            }
            this.h[i4] += localObject4;
            this.i[i4].e += localObject4;
            arrayOfInt[i4] -= localObject4;
            localObject5 = locald2.e();
            if (i5 != 0) {
              break label812;
            }
          } while (!bool);
          this.h[i4] -= localObject4;
          arrayOfInt[i4] += localObject4;
          localObject5 = locald2.f();
          if (i5 != 0) {
            break label833;
          }
        } while (!bool);
        localObject1 -= localObject4;
        c();
        if (!bool) {
          break;
        }
      }
    }
    label842:
    Object localObject3 = 0;
    Object localObject4 = this.b.w();
    do
    {
      if (!((a.c.m)localObject4).e()) {
        break;
      }
      localObject5 = ((a.c.m)localObject4).a();
      i3 = ((a.c.d)localObject5).d();
      localObject3 += this.h[i3] * this.e[i3];
      paramn2.a(localObject5, this.h[i3]);
      ((a.c.m)localObject4).f();
      if (i5 != 0) {
        break label951;
      }
      if (bool) {
        break label949;
      }
    } while (!bool);
    if (i5 == 0) {
      this.l.c();
    }
    label949:
    label951:
    return localObject3;
  }
  
  private void a(e parame1, e parame2, int[] paramArrayOfInt1, int[] paramArrayOfInt2, int[] paramArrayOfInt3, Object[] paramArrayOfObject)
  {
    int i8 = j.r;
    boolean bool = j.q;
    this.m.d();
    int i1 = 0;
    if (i1 < this.k)
    {
      if (i8 != 0) {}
    }
    else
    {
      do
      {
        this.f[i1] = 2147483647;
        paramArrayOfObject[i1] = null;
        i1++;
        if (bool) {
          break label86;
        }
        if (!bool) {
          break;
        }
        this.o.clear();
      } while (i8 != 0);
      this.f[parame1.f()] = 0;
    }
    label86:
    this.m.a(parame1, 0);
    break label548;
    if (!this.m.a()) {
      this.l.d += 1;
    }
    label179:
    int i6;
    int i3;
    label508:
    do
    {
      e locale1 = this.m.c();
      int i2 = locale1.f();
      if (i8 == 0)
      {
        this.o.add(locale1);
        if (parame2 == locale1) {}
      }
      else
      {
        int i4;
        e locale2;
        int i5;
        do
        {
          i6 = this.f[i2] + this.g[i2];
          locald = locale1.h();
          do
          {
            do
            {
              if (locald == null) {
                break label536;
              }
              i4 = locald.d();
              if (i8 != 0) {
                break label179;
              }
              if (bool) {
                break;
              }
              if ((paramArrayOfInt2[i4] >= 1) && (this.i[i4].e != this.i[i4].c))
              {
                locale2 = locald.f();
                i3 = locale2.f();
                i5 = i6 - this.g[i3] + paramArrayOfInt1[i4];
                if (i8 != 0) {
                  continue;
                }
                if (i5 < this.f[i3])
                {
                  if (i8 == 0) {
                    if (this.f[i3] == 2147483647)
                    {
                      if (i8 == 0)
                      {
                        if (i5 < 0)
                        {
                          a.i.n.a("insert: Out edges smaller 0: " + this.n.get(locale1) + " -> " + this.n.get(locale2) + " : " + i5);
                          if (i8 != 0) {
                            break label517;
                          }
                          if (!bool) {
                            break label508;
                          }
                        }
                        this.m.a(locale2, i5);
                        if (i8 != 0) {
                          break label517;
                        }
                      }
                      if (!bool) {
                        break label508;
                      }
                    }
                  }
                  if (i8 == 0)
                  {
                    if (i5 < 0)
                    {
                      a.i.n.a("decrease: Out edges smaller 0: " + this.n.get(locale1) + " -> " + this.n.get(locale2) + " : " + i5);
                      if (i8 != 0) {
                        break label517;
                      }
                    }
                  }
                  else {
                    if (!bool) {
                      break label508;
                    }
                  }
                  this.m.b(locale2, i5);
                  this.f[i3] = i5;
                  paramArrayOfObject[i3] = locald;
                }
              }
              locald = locald.i();
            } while (!bool);
          } while (i8 != 0);
          locald = locale1.i();
          if (locald == null) {
            break;
          }
          i4 = locald.d();
          if (i8 != 0) {
            break label782;
          }
          if ((i8 == 0) && (bool)) {
            break label791;
          }
        } while (bool);
        if ((paramArrayOfInt3[i4] >= 1) && (this.i[i4].b().k() <= 1))
        {
          locale2 = locald.e();
          i3 = locale2.f();
          i5 = i6 - this.g[i3] - paramArrayOfInt1[i4];
          if (i8 == 0) {
            if (i5 < 0) {
              a.i.n.a("In edges smaller 0: " + i5);
            }
          }
          if (i8 != 0) {
            break label770;
          }
          if (i5 < this.f[i3])
          {
            if (i8 == 0) {
              if (this.f[i3] == 2147483647)
              {
                this.m.a(locale2, i5);
                if (i8 != 0) {
                  break label754;
                }
                if (!bool) {
                  break label745;
                }
              }
            }
            this.m.b(locale2, i5);
            this.f[i3] = i5;
            paramArrayOfObject[i3] = locald;
          }
        }
        a.c.d locald = locald.j();
        if (!bool) {
          break;
        }
      }
      i6 = this.f[parame2.f()];
    } while (i8 != 0);
    label517:
    label536:
    label548:
    label745:
    label754:
    if (i6 == 0) {
      return;
    }
    label770:
    label782:
    label791:
    int i7 = 0;
    do
    {
      if (i7 >= this.o.size()) {
        break;
      }
      i3 = ((e)this.o.get(i7)).f();
      this.g[i3] += this.f[i3] - i6;
      i7++;
    } while (!bool);
  }
  
  public void c()
  {
    int i6 = j.r;
    boolean bool = j.q;
    int i1 = 0;
    label127:
    do
    {
      if (i1 >= this.p.size()) {
        break;
      }
      ArrayList localArrayList = (ArrayList)this.p.get(i1);
      do
      {
        if (localArrayList.size() != 0)
        {
          d locald = (d)localArrayList.get(0);
          a.c.d locald1 = locald.b().a();
          a.c.d locald2 = null;
          a.c.d locald3 = null;
          int i2 = 0;
          if (this.h[locald1.d()] > 0) {
            locald3 = locald1;
          }
          do
          {
            do
            {
              if (locald3 != null)
              {
                if (i6 != 0) {
                  break label127;
                }
                if (this.h[a(locald1).d()] > 0) {
                  locald2 = a(locald1);
                }
              }
              locald1 = this.q[locald1.d()];
              i2++;
              if (i6 != 0) {
                break label169;
              }
              if ((locald2 == null) && (i2 < localArrayList.size() + 3)) {
                break;
              }
            } while (i6 != 0);
          } while (bool);
          if (locald2 != null)
          {
            int i3 = 0;
            this.s[0][0] = locald2;
            this.t[0][0] = locald2;
            int i4 = 0;
            locald1 = this.r[locald2.d()];
            do
            {
              if (locald1 == locald2) {
                break;
              }
              if (i6 != 0) {
                break label405;
              }
              if (bool) {
                break label404;
              }
              a.c.d locald4;
              a.c.d locald5;
              if (i4 == 0)
              {
                locald4 = locald1;
                locald5 = a(locald1);
                if (i6 != 0) {
                  break label284;
                }
                if (!bool) {}
              }
              else
              {
                locald5 = locald1;
                locald4 = a(locald1);
              }
              if (i6 == 0) {
                if (this.h[locald4.d()] > 0) {
                  this.t[i4][i3] = locald4;
                }
              }
              if (i6 == 0)
              {
                if (this.h[locald5.d()] > 0)
                {
                  i3 += i4;
                  if (i6 == 0) {
                    if (i3 > 3) {
                      throw new RuntimeException("Too many intervals !!!!");
                    }
                  }
                  i4 = 1 - i4;
                  this.s[i4][i3] = locald5;
                  this.t[i4][i3] = locald5;
                }
                locald1 = this.r[locald1.d()];
              }
            } while (!bool);
            if (i6 != 0) {
              continue;
            }
            if (i3 == 3)
            {
              int i5 = 0;
              do
              {
                if (i5 >= 4) {
                  break label578;
                }
                if (bool) {
                  break;
                }
                a.c.d locald6 = this.s[0][i5];
                do
                {
                  do
                  {
                    if (locald6 == this.t[0][i5]) {
                      break;
                    }
                    this.e[a(locald6).d()] = 10000;
                    if (i6 != 0) {
                      break label509;
                    }
                    locald6 = this.r[locald6.d()];
                    if (bool) {
                      break label507;
                    }
                  } while (!bool);
                } while (i6 != 0);
                locald6 = this.t[1][i5];
                if (locald6 != this.s[1][i5])
                {
                  this.e[a(locald6).d()] = 10000;
                  locald6 = this.q[locald6.d()];
                }
                for (;;)
                {
                  if (i6 == 0) {
                    if (!bool)
                    {
                      if (!bool) {
                        break;
                      }
                      if (i6 != 0) {
                        continue;
                      }
                      i5++;
                    }
                  }
                }
              } while (!bool);
            }
          }
        }
        i1++;
      } while (i6 != 0);
    } while (!bool);
    label169:
    label507:
    label509:
    return;
  }
  
  private a.c.d a(a.c.d paramd)
  {
    a.c.d[] arrayOfd = this.i[paramd.d()].c();
    if (j.r == 0) {
      if (arrayOfd[0] != paramd) {
        return arrayOfd[0];
      }
    }
    return arrayOfd[1];
  }
  
  public void a(a.c.q paramq)
  {
    int i3 = j.r;
    boolean bool = j.q;
    a.i.n.a("");
    a.i.n.a("Check invariant");
    a.c.m localm = paramq.w();
    do
    {
      if (!localm.e()) {
        break;
      }
      a.c.d locald = localm.a();
      String str = this.n.get(locald.e()) + " -> " + this.n.get(locald.f());
      int i1 = locald.d();
      int i2 = this.e[locald.d()] + this.g[locald.e().f()] - this.g[locald.f().f()];
      if (i3 == 0) {
        if (this.h[i1] < 0)
        {
          a.i.n.a("Negative flow");
          throw new RuntimeException("Negative flow: " + str);
        }
      }
      if (i3 == 0)
      {
        if (this.h[i1] > this.d[i1])
        {
          a.i.n.a("Flow > capacity");
          throw new RuntimeException("flow > capacity: " + str);
        }
        localm.f();
      }
    } while (!bool);
  }
  
  private static class a_
  {
    private String a;
    private mb b = new mb();
    int c;
    int d;
    
    public void a()
    {
      this.c = 0;
      this.d = 0;
      this.a = "0";
      this.b.a();
      this.b.g();
    }
    
    public void c()
    {
      this.a = this.b.toString();
    }
    
    public String toString()
    {
      return "\nMinCostFlow-Statistics:\n   Time: " + this.a + "\n   Augmentations : " + this.c + "\n   ExtractMins: " + this.d;
    }
  }
}



/* Location:           E:\idea\

 * Qualified Name:     a.f.h.d.z

 * JD-Core Version:    0.7.0.1

 */